package com.slf.engine.listener;


import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletContextEvent;

import org.apache.log4j.Logger;
import org.apache.log4j.Priority;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;

import com.slf.engine.base.IBaseDao;
import com.slf.engine.bo.WaitBean;
import com.slf.engine.common.SysContext;
import com.slf.engine.services.helper.ServiceHelper;
import com.slf.engine.threads.MainThread;


public class EngineListener extends ContextLoaderListener{

	private static final Logger log = Logger.getLogger(EngineListener.class);
	public void contextInitialized(ServletContextEvent event) {
		
		if(null == event.getServletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE))
		{
			super.contextInitialized(event);
		}
		
		WebApplicationContext context = (WebApplicationContext) event.getServletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
		
		SysContext.IS_TREAD_RUN = true;
		new MainThread(context).start();
	}
	
	
	public void contextDestroyed(ServletContextEvent event) {
		log.log(Priority.INFO, "关闭服务--清空充值请求");
		SysContext.IS_TREAD_RUN = false;
		SysContext.QUERY_MAP.clear();
		SysContext.ORDER_LIST.clear();
		SysContext.NOTICE_LIST.clear();
	}
}
